const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin')

module.exports = {
  entry: './src/main.js', // 打包入口文件
  output: {
    path: path.resolve(__dirname, 'dist'), // 打包输出文件目录
    filename: 'bundle.js', // 打包输出文件名
    publicPath: '/dist/' // 资源打包完后所设置的根目录所在地
  },
  module: {
    rules: [
      {
        test: /.png$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10 * 1024 // 超过10kb的使用url-loader,使用这个配置时必须安装file-loader，当超过10kb的文件，webpack还是会去用file-loader
          }
        }
      },
      {
        test: /.less$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
      },
      {
        test: /.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      },
      {
        test: /.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      },
      {
        test: /.vue$/,
        use: ['vue-loader']
      },
      {
        test: /\.(js | vue)$/,
        exclude: /node_modules/,
        use: 'eslint-loader',
        enfore: 'pre'
      },
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin(),
    new MiniCssExtractPlugin(),
    new OptimizeCssAssetsWebpackPlugin()
  ]
}
